<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Models\UserCoupon;

class UserCouponController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {   
        $param = [];
        $query = UserCoupon::query();
        if($request->keyword) {
            $keyword = trim($request->keyword);
            $query->whereHas('user', function ($query) use ($keyword) {
                $query->where('truename', 'like', '%'.$keyword.'%')
                      ->orWhere('mobile','like','%'.$keyword.'%');
            });
        }  
        if($request->user_id){
            $query->where(['user_id'=>$request->user_id]);
        }
            
        $list  = $query->with(['coupon','user'])
                       ->paginate(10);
        return view('admin.user-coupon.index',compact('list','param'));
    }

   
}
